package com.zjsru.leetcode75.level1;

/**
 * @Author: CookLee
 * @Date: 2022/10/27
 *
 * 一维数组的动态和
 *
 * 输入：nums = [1,2,3,4]
 * 输出：[1,3,6,10]
 * 解释：动态和计算过程为 [1, 1+2, 1+2+3, 1+2+3+4] 。
 */
public class RunningSum {
    
    public int[] runningSum(int[] nums) {
        int[] ints = new int[nums.length];
        int ans = 0, i = 0;
        for (int num : nums) {
            ans += num;
            ints[i] = ans;
            i++;
        }
        return ints;
    }
    
    public static void main(String[] args) {
        RunningSum runningSum = new RunningSum();
        int[] nums = new int[] {1, 2, 3, 4};
        System.out.println(runningSum.runningSum(nums));
    }
}
